package com.zsck.zsgy.ui.main.fragment.simplecircle

import androidx.lifecycle.MutableLiveData
import com.zsck.zsgy.api.ApiService
import com.zsck.zsgy.base.BaseRepository
import com.zsck.zsgy.http.RetrofitManager
import com.zsck.zsgy.http.exception.ApiException
import com.zsck.zsgy.ui.main.bean.SimpleCircleActivityBean
import com.zsck.zsgy.ui.main.bean.SimpleCircleListBean
import com.zsck.zsgy.util.Constants
import com.zsck.zsgy.util.isNotNull
import kotlinx.coroutines.CoroutineScope

class SimpleCircleRepo(
    coroutineScope: CoroutineScope,
    errorLiveData: MutableLiveData<ApiException>
) :
    BaseRepository(coroutineScope, errorLiveData) {

    fun simpleCircleList(
        currentPage: Int,
        simpleCircle: Int,
        simpleCircleModel:MutableLiveData<SimpleCircleListBean>
    ) {
        var body = HashMap<String, Any>()
        body.put("currentPage",currentPage)
        body.put("pageSize",20)
        body.put("configLoation",7)
        body.put("simpleCircle",simpleCircle)
        body.put("cityName","")


        launch(block ={
            RetrofitManager.getApiService(ApiService::class.java)
                .simpleCircleList(body)
                .data
        },success = {
            simpleCircleModel.postValue(it)
        })
    }

    fun simpleCircleActivity(
        currentPage :Int,
        keyword:String,
        simpleCircleActivityModel: MutableLiveData<SimpleCircleActivityBean>
    ){
        var body = HashMap<String, Any>()
        body.put("currentPage",currentPage)
        if(keyword.isNotNull())body.put("keyword",keyword)
        body.put("pageSize",20)
        body.put("cityId",Constants.CITY_ID)

        launch(block ={
            RetrofitManager.getApiService(ApiService::class.java)
                .simpleCircleActivity(body)
                .data
        },success = {
            simpleCircleActivityModel.postValue(it)
        })
    }

}